﻿Imports System.Data.OleDb
Partial Class UploadStyle
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.User.Identity.IsAuthenticated Then
            Response.Write("To upload any style, you need to be authenticated. Please use the <a href='Login.aspx'>Login</a> page to authenticate yourself.")
            Response.End()
        End If

        TodayDate.Text = DateTime.Now.ToString

        Dim title As String = PictTitle.Text

        If ImageUpload.HasFile Then

            Dim filename = ImageUpload.FileName
            Dim webrootfolder = Request.MapPath(".")
            Dim imagefolder = webrootfolder & "/UsersStyles/"
            ImageUpload.SaveAs(imagefolder & filename)
            Dim oleDbConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("mobilestandardsdb").ConnectionString)
            Dim sql As String = "INSERT INTO UsersUpload (Category, Style, Gender,Ethnic,Description,TodayDate,PicTitle,ProfileImage,UserName ) VALUES (@Category, @Style, @Gender,@Ethnic,@Description,@TodayDate,@PicTitle,@ProfileImage,@UserName)"
            Dim cmd As New OleDbCommand(sql, oleDbConn)
            cmd.Parameters.AddWithValue("@Category", CategoryDrop.SelectedValue)
            cmd.Parameters.AddWithValue("@Style", StyleDrop.SelectedValue)
            cmd.Parameters.AddWithValue("@Gender", GenderDrop.SelectedValue)
            cmd.Parameters.AddWithValue("@Ethnic", EthnicDrop.SelectedValue)
            cmd.Parameters.AddWithValue("@Description", Discription.Text)
            cmd.Parameters.AddWithValue("@TodayDate", TodayDate.Text)
            cmd.Parameters.AddWithValue("@PicTitle", PictTitle.Text)
            cmd.Parameters.AddWithValue("@ProfileImage", "UsersStyles/" & filename)
            cmd.Parameters.AddWithValue("@UserName", User.Identity.Name)
            oleDbConn.Open()
            cmd.ExecuteNonQuery()
            oleDbConn.Close()
            Response.Redirect("StyleDetails.aspx")

        End If
    End Sub

    
End Class
